package com.shop.loan.controller;

import com.shop.loan.annotation.LoginAuth;
import com.shop.loan.model.Goods;
import com.shop.loan.model.common.Constant;
import com.shop.loan.model.common.ResResult;
import com.shop.loan.model.vo.GoodsVo;
import com.shop.loan.service.GoodsService;
import com.shop.loan.util.PageGoodsUtil;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;

@Api(value = "商品管理", tags = "商品管理")
@RestController
@RequestMapping(Constant.appPrefex + "/goods")
public class GoodsController {

    @Resource
    GoodsService goodsService;

    @LoginAuth
    @ApiOperation("商品列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "商品名称", dataType = "int"),
            @ApiImplicitParam(name = "isHot", value = "是否热门  1：热门  0：非热门", dataType = "int"),
            @ApiImplicitParam(name = "classifyId", value = "所属类别", dataType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "页面条数", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageNum", value = "第几页  从1开始", dataType = "int", required = true),
    })
    @ApiResponses({
            @ApiResponse(code = 1, message = "成功", response = Goods.class)
    })
    @PostMapping("/list")
    public ResResult list(@ApiIgnore GoodsVo goods) {
        PageGoodsUtil pageUtil = goodsService.list(goods);
        return new ResResult(pageUtil.getDataList(), pageUtil.getTotalPage(), pageUtil.getTotal());
    }

    @ApiOperation("商品详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "商品id", dataType = "int"),
    })
    @ApiResponses({
            @ApiResponse(code = 1, message = "成功", response = Goods.class)
    })
    @PostMapping("/detail")
    public ResResult detail(@ApiIgnore GoodsVo goods) {
        return goodsService.detail(goods);
    }

}
